# 获取屏幕分辨率
# 方法一：
from win32 import win32api, win32gui, win32print
from win32.lib import win32con

from win32.win32api import GetSystemMetrics


def get_real_resolution():
    """获取真实的分辨率"""
    hDC = win32gui.GetDC(0)
    # 横向分辨率
    w = win32print.GetDeviceCaps(hDC, win32con.DESKTOPHORZRES)
    # 纵向分辨率
    h = win32print.GetDeviceCaps(hDC, win32con.DESKTOPVERTRES)
    return w, h


def get_screen_size():
    """获取缩放后的分辨率"""
    w = GetSystemMetrics(0)
    #或写成 GetSystemMetrics(win32con.SM_CXSCREEN)
    h = GetSystemMetrics(1)
    #或写成 GetSystemMetrics(win32con.SM_CYSCREEN)
    return w, h

real_resolution = get_real_resolution()
screen_size = get_screen_size()
print(real_resolution)
print(screen_size)

screen_scale_rate = round(real_resolution[0] / screen_size[0], 2)
print(screen_scale_rate)


# 方法二：
import tkinter  # 导入tkinter库，Python自带的GUI库

screen_width = tkinter.Tk().winfo_screenwidth()  # 计算机屏幕水平分辨率
screen_height = tkinter.Tk().winfo_screenheight()  # 计算机屏幕垂直分辨率

print(screen_width)
print(screen_height)
